package com.clkj.nangang.mvp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.clkj.nangang.R;
import com.clkj.nangang.common.Config;
import com.clkj.nangang.mvp.model.JianduWorkerModel;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * 干部
 * Created by Administrator on 2017/8/4.
 */

public class CadreListAdapter extends BaseAdapter {

    private Context context;
    private List<JianduWorkerModel> jianduWorkerModelList;

    public CadreListAdapter(Context context, List<JianduWorkerModel> jianduWorkerModelList) {
        this.context = context;
        this.jianduWorkerModelList = jianduWorkerModelList;
    }

    @Override
    public int getCount() {
        return jianduWorkerModelList.size();
    }

    @Override
    public Object getItem(int position) {
        return jianduWorkerModelList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        localViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_cadrelist, null);
            holder = new localViewHolder();

            holder.imageHead = (ImageView) convertView.findViewById(R.id.image_head);
            holder.tvName = (TextView) convertView.findViewById(R.id.tv_name);
            holder.tvPhone = (TextView) convertView.findViewById(R.id.tv_phone);
            holder.tvPosition = (TextView) convertView.findViewById(R.id.tv_position);
            holder.tvDuty = (TextView) convertView.findViewById(R.id.tv_duty);

            convertView.setTag(holder);
        } else {
            holder = (localViewHolder) convertView.getTag();
        }

        holder.tvName.setText("姓名:" + jianduWorkerModelList.get(position).getName());
        holder.tvPhone.setText("电话:" + jianduWorkerModelList.get(position).getTelephone());
        holder.tvPosition.setText("职位:" + jianduWorkerModelList.get(position).getPosition());
        holder.tvDuty.setText("负责:" + jianduWorkerModelList.get(position).getJobs());

        Picasso.with(context).load(Config.URL_BASE_FOR_PIC_IN_USE + jianduWorkerModelList.get(position).getImgUrl()).
                placeholder(R.drawable.ic_error).error(R.drawable.defaultpic).into(holder.imageHead);

        return convertView;
    }

    class localViewHolder {

        private ImageView imageHead;
        private TextView tvName;
        private TextView tvPhone;
        private TextView tvPosition;
        private TextView tvDuty;

    }

}
